﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Data;

namespace Kiosk
{
    /// <summary>
    /// Interaction logic for FocusedAreasOfStudy.xaml
    /// </summary>
    public partial class FocusedAreasOfStudy : Window
    {
        private DataSet dsFAOS = new DataSet();
        int returnCount = 0;
        bool art;
        bool business;
        bool handhservices;
        bool industry;
        bool letandscience;

        public FocusedAreasOfStudy()
        {
            InitializeComponent();
            sGlobals.selectedAOSID = new List<String>();
            art = false;
            business = false;
            handhservices = false;
            industry = false;
            letandscience = false;
        }

        private void btnFAOSLogOut_Click(object sender, RoutedEventArgs e)
        {
            sGlobals.logout();
            
        }

        private void btnViewSavedMentors_Click(object sender, RoutedEventArgs e)
        {
            DataSet temp = new DataSet();
            string sql = "SELECT count(*) AS c FROM favorite_mentors WHERE user_id = ( SELECT user_id FROM users WHERE username = '" + sGlobals.currentUsername + "' ) " + 
                "AND mentor_id in (SELECT mentor_id FROM mentor m WHERE m.deletion_date IS NULL)";
            int rowsAffected = 0;
            try
            {
                temp = sGlobals.dbWrapper.ExecuteSQLStatement(sql, ref rowsAffected);

                if (temp.Tables[0].Rows[0]["c"].ToString() == "0"/*rowsAffected == 0*/)
                {
                    WarningMessage warning = new WarningMessage();
                    warning.lblMessage.Content = "You have no saved mentors";
                    warning.ShowDialog();
                }
                else
                {
                    sGlobals.favoriteMentors.Show();
                    this.Hide();
                }
            }
            catch (Exception ex)
            {
                if (!sGlobals.hasLogout)
                {
                    WarningMessage warning = new WarningMessage();
                    warning.lblMessage.Content = "There was a problem retrieving your saved mentors.\r\nIf the problem persists, please contact your system administrator.";
                    warning.ShowDialog();
                }
            }
        }

        private void btnAdvancedSearch_Click(object sender, RoutedEventArgs e)
        {
            sGlobals.filterMentors.Show();
            this.Hide();
        }

        private void btnFAOSSubmit_Click(object sender, RoutedEventArgs e)
        {
            if (sGlobals.selectedAOSID.Count() == 0)
            {
                lblSubmitMessage0.Content = "Please select at least 1";
                lblSubmitMessage1.Content = "Focused Area of Study";
            }
            else
            {
                lblSubmitMessage0.Content = "";
                lblSubmitMessage1.Content = "";
                sGlobals.pathways.Show();
                this.Hide();
            }
        }

        private void btnArt_Click(object sender, RoutedEventArgs e)
        {
            string sqlQuery = "SELECT focus_id FROM lkup_focus_area WHERE focus_name = 'ART'";
            try
            {
                dsFAOS = sGlobals.dbWrapper.ExecuteSQLStatement(sqlQuery, ref returnCount);

                if (art == false)
                {
                    if (returnCount == 1)
                    {
                        art = true;
                        bart.Background = Brushes.Gold;
                        bart.BorderBrush = Brushes.Gold;
                        bart.BorderThickness = new Thickness(20);
                        btnArt.Opacity = .4;
                        sGlobals.selectedAOSID.Add(dsFAOS.Tables[0].Rows[0]["focus_id"].ToString());
                    }
                }
                else
                {
                    art = false;
                    bart.Background = Brushes.White;
                    bart.BorderBrush = Brushes.White;
                    bart.BorderThickness = new Thickness(0);
                    btnArt.Opacity = 1;
                    sGlobals.selectedAOSID.Remove(dsFAOS.Tables[0].Rows[0]["focus_id"].ToString());
                }
            }
            catch (Exception ex)
            {
                if (!sGlobals.hasLogout)
                {
                    Console.WriteLine("There was an error connecting to the database with Exception: {0}", ex.Message);
                }
            }
            returnCount = 0;
            btnFAOSSubmit.Focus();
        }

        private void btnBusiness_Click(object sender, RoutedEventArgs e)
        {
            string sqlQuery = "SELECT focus_id FROM lkup_focus_area WHERE focus_name = 'BUSINESS AND MARKETING'";
            try
            {
                dsFAOS = sGlobals.dbWrapper.ExecuteSQLStatement(sqlQuery, ref returnCount);

                if (business == false)
                {
                    if (returnCount == 1)
                    {
                        business = true;
                        bbusiness.Background = Brushes.DarkGreen;
                        bbusiness.BorderBrush = Brushes.DarkGreen;
                        bbusiness.BorderThickness = new Thickness(20);
                        btnBusiness.Opacity = .4;
                        sGlobals.selectedAOSID.Add(dsFAOS.Tables[0].Rows[0]["focus_id"].ToString());
                    }
                }
                else
                {
                    business = false;
                    bbusiness.Background = Brushes.White;
                    bbusiness.BorderBrush = Brushes.White;
                    bbusiness.BorderThickness = new Thickness(0);
                    btnBusiness.Opacity = 1;
                    sGlobals.selectedAOSID.Remove(dsFAOS.Tables[0].Rows[0]["focus_id"].ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was error connecting to the database with exception: {0}", ex.Message);
            }
            returnCount = 0;
            btnFAOSSubmit.Focus();
        }

        private void btnHHS_Click(object sender, RoutedEventArgs e)
        {
            string sqlQuery = "SELECT focus_id FROM lkup_focus_area WHERE focus_name = 'HEALTH AND HUMAN SERVICES'";
            try
            {
                dsFAOS = sGlobals.dbWrapper.ExecuteSQLStatement(sqlQuery, ref returnCount);

                if (handhservices == false)
                {
                    if (returnCount == 1)
                    {
                        handhservices = true;
                        bhhservices.Background = Brushes.Gold;
                        bhhservices.BorderBrush = Brushes.Gold;
                        bhhservices.BorderThickness = new Thickness(20);
                        btnHHS.Opacity = .4;
                        sGlobals.selectedAOSID.Add(dsFAOS.Tables[0].Rows[0]["focus_id"].ToString());
                    }
                }
                else
                {
                    handhservices = false;
                    bhhservices.Background = Brushes.White;
                    bhhservices.BorderBrush = Brushes.White;
                    bhhservices.BorderThickness = new Thickness(0);
                    btnHHS.Opacity = 1;
                    sGlobals.selectedAOSID.Remove(dsFAOS.Tables[0].Rows[0]["focus_id"].ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem connecting to the database with exception: {0}", ex.Message);
            }
            returnCount = 0;
            btnFAOSSubmit.Focus();
        }

        private void btnIndustry_Click(object sender, RoutedEventArgs e)
        {
            string sqlQuery = "SELECT focus_id FROM lkup_focus_area WHERE focus_name = 'INDUSTRY'";
            try
            {
                dsFAOS = sGlobals.dbWrapper.ExecuteSQLStatement(sqlQuery, ref returnCount);

                if (industry == false)
                {
                    if (returnCount == 1)
                    {
                        industry = true;
                        bindustry.Background = Brushes.DarkGreen;
                        bindustry.BorderBrush = Brushes.DarkGreen;
                        bindustry.BorderThickness = new Thickness(20);
                        btnIndustry.Opacity = .4;
                        sGlobals.selectedAOSID.Add(dsFAOS.Tables[0].Rows[0]["focus_id"].ToString());
                    }
                }
                else
                {
                    industry = false;
                    bindustry.Background = Brushes.White;
                    bindustry.BorderBrush = Brushes.White;
                    bindustry.BorderThickness = new Thickness(0);
                    btnIndustry.Opacity = 1;
                    sGlobals.selectedAOSID.Remove(dsFAOS.Tables[0].Rows[0]["focus_id"].ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem connecting to the database", ex.Message);
            }
            returnCount = 0;
            btnFAOSSubmit.Focus();
        }

        private void btnLS_Click(object sender, RoutedEventArgs e)
        {
            string sqlQuery = "SELECT focus_id FROM lkup_focus_area WHERE focus_name = 'LETTERS AND SCIENCES'";
            try
            {
                dsFAOS = sGlobals.dbWrapper.ExecuteSQLStatement(sqlQuery, ref returnCount);

                if (letandscience == false)
                {
                    if (returnCount == 1)
                    {
                        letandscience = true;
                        blands.Background = Brushes.Gold;
                        blands.BorderBrush = Brushes.Gold;
                        blands.BorderThickness = new Thickness(20);
                        btnLS.Opacity = .4;
                        sGlobals.selectedAOSID.Add(dsFAOS.Tables[0].Rows[0]["focus_id"].ToString());
                    }
                }
                else
                {
                    letandscience = false;
                    blands.Background = Brushes.White;
                    blands.BorderBrush = Brushes.White;
                    blands.BorderThickness = new Thickness(0);
                    btnLS.Opacity = 1;
                    sGlobals.selectedAOSID.Remove(dsFAOS.Tables[0].Rows[0]["focus_id"].ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("There was a problem connecting to the database", ex.Message);
            }
            returnCount = 0;
            btnFAOSSubmit.Focus();
        }
    }
}
